// initial state
// shape: [{ id, quantity }]
const state = () => ({
  items: [],
  allprice: 0

})

// getters
const getters = {

}
// mutations
const mutations = {
  initprice(state) {
    state.allprice = 0
    state.items.map(pro => { state.allprice = state.allprice + pro.count * pro.price})
  },
  addpro(state, pro) {
    pro.count = 1
    state.allprice = pro.count * pro.price
    state.items.push(pro)
  }
}

// actions
const actions = {
  addcar({commit}, pro) {

    commit('addpro', pro)
  }
}


export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
